package com.bringway.framework.factory;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.LinkedHashMap;
import java.util.Map;

public class HelpCacheFactory {
	
	private static HelpCacheFactory instance;

	public static Map propsMap = new LinkedHashMap();
	
	private HelpCacheFactory() {
		initCahce();
	}

	public static HelpCacheFactory getCacheInstance() {
		if (instance == null) {
			instance = new HelpCacheFactory();
		}
		return instance;
	}

	public void initCahce() {
		try {
			HelpCacheFactory.readProperties();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public String getHelp(String key){
		return (String) propsMap.get(key);
	}
	
	public static void readProperties() throws Exception{
		InputStream inputStream = HelpCacheFactory.class.getClassLoader().getResourceAsStream("help.properties");
        BufferedReader br = new BufferedReader(new InputStreamReader(inputStream,"UTF-8"));
        String pair = "";
		while((pair=br.readLine())!=null){
            String key = pair.substring(0,pair.indexOf("="));
            String value = pair.substring(pair.indexOf("=")+1);
            propsMap.put(key, value);
        }
        inputStream.close();
        br.close();
	}
}
